
const ObjectId = require('mongoose').Types.ObjectId
export default class Page  {
    constructor(){

    }
    async pageQuery (  Model, pageNum = 1 , pageSize = 10, value , condition = {} ) {
        if (value) {
            return await Model.find(
                {'create_date': {"$lt":  Number(value)  },
                    ...condition
                }, {
                    __v : 0
                })
                .limit( Number(pageSize) )
                .sort({'_id':-1})
        }else {
            return await  Model.find({
                ...condition
                },{
                    __v : 0
                })
                .limit( Number(pageSize) )
                .sort({'_id':-1})
        }
    }
    PageResult ( pageNum, pageSize , res ) {

        const lastValue = res.length ? res[res.length - 1]['create_date'] : ''
        return {
            pageNum :pageNum ,
            pageSize : pageSize ,
            data: res ,
            lastValue : lastValue ,
            hasMore: res.length == pageSize ? true : false
        }
    }
}

